1196B - Odd Sum Segments - CodeForces Solution


constructive algorithms math *1200

Please click on ads to support us..

Python Code:

from sys import stdin, stdout
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_arr(): return list(map(int, sys.stdin.readline().strip().split()))
t = int(input())
while t:
      t-=1
      n,k = get_ints()
            a = get_arr()
      cntodd = 0
      for i in range(0,len(a)):
        if a[i]%2==1:
            cntodd+=1
      if k > cntodd:
        print('NO')
      else:
        if (cntodd - k)%2==1:
            print('NO')
        else:
            print('YES')
            inds = []
            ans = []

            for i in range(0,len(a)):
                if a[i]%2==1:
                    inds.append(int(i))  
                                    for i in range(cntodd-k,len(inds)-1):
              print(inds[i]+1,end=' ')
                        print(n)    







C++ Code:

//! Bismillahi-Rahamanirahim.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define vll vector<ll>
#define vs vector<string>
#define vvll(a,n,v) vector<vector<ll>> a(n,vector<ll>(n,v));
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define sp ' '
#define eps 1e-12
#define pi (2*acos(0))
#define sz(n) (int)(n).size()
#define mem(x,y) memset(&x[0],y,sizeof(x))
#define sfor(i,s,n,m) for(ll i=s; i<n; i+=m)
#define refor(i,n,s,m) for(ll i=n-1; i>=s; i-=m)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define torad(x) ((x) * ((2*acos(0))/180.0))
#define todeg(x) ((x) * (180.0/(2*acos(0))))
#define fixangle(x) ((x) > 1 ? 1 : (x) < -1 : (x))
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//-------------------------------------------------------------------------//
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>pbd_set;
//-------------------------------------------------------------------------//
//---------------------------main()------------------------------//
int main()
{
    fast();//9
    ll t=1;
    cin >> t;
    while(t--)
    {
        ll n,k,c=0;
        cin >> n >> k;
        vll a(n),b;
        sfor(i,0,n,1)
        {
            cin >> a[i];
            if(a[i]%2!=0)
                {c++;b.pb(i+1);}
        }
        if(c<k)
            cout << "No" << endl;
        else if(c%2==k%2)
        {
            cout << "Yes" << endl;
            sfor(i,0,k-1,1)
            {
                cout << b[i] << sp;
            }
            cout << n << endl;
        }
        else
            cout << "No" << endl;
    }
    return 0;
}
//---------------------------main()------------------------------//
/*

*/


Comments

Submit
0 Comments
More Questions

Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array